package com.hbnu.system.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hbnu.system.core.base.CommonPage;
import com.hbnu.system.core.base.Rest;
import com.hbnu.system.model.dto.AwardAddDTO;
import com.hbnu.system.model.dto.AwardDTO;
import com.hbnu.system.model.dto.CheckBackDTO;
import com.hbnu.system.model.dto.SearchPageDTO;
import com.hbnu.system.model.entity.Award;
import com.hbnu.system.model.entity.Awardfile;
import com.hbnu.system.model.query.AwardPageQuery;
import com.hbnu.system.model.vo.AwardVO;
import com.hbnu.system.service.AwardfileService;
import com.hbnu.system.service.IAwardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2023-05-16
 */
@RestController
@RequestMapping("/award")
@Api(tags = "成果模块")
public class AwardController {

    @Autowired
    IAwardService iAwardService;
    @Autowired
    AwardfileService awardfileService;



    @ApiOperation("成果-正式录入")
    @PostMapping("/addAward")
    public Rest<Boolean> AddAward(@RequestBody Award award){
        boolean add = iAwardService.addAward(award);
        return add ? Rest.success():Rest.failed();
    }
    @ApiOperation("成果-修改")
    @PostMapping("/updateaward")
    public Rest<Boolean> updateaward(@RequestBody Award award) {
        boolean update = iAwardService.updateAward(award);
        return update ? Rest.success() : Rest.failed();
    }
    @ApiOperation("成果-删除")
    @GetMapping("/Deleteaward")
    public Rest<Boolean> Deleteaward(String ID) throws IOException {
        boolean delete = iAwardService.deleteaward(ID);
        return delete ? Rest.success() : Rest.failed();
    }
    @ApiOperation("成果-初次录入")
    @PostMapping("/addAwardDTO")
    public Rest<Boolean> AddAward(@RequestBody AwardAddDTO awardAddDTO){
        boolean add = iAwardService.addAward(awardAddDTO);
        return add?Rest.success() : Rest.failed();
    }

    @ApiOperation("成果-提交")
    @PostMapping("/ReCommitaward")
    public Rest<Boolean> ReCommitAward(String id){
        boolean add = iAwardService.ReCommitAward(id);
        return  add? Rest.success() : Rest.failed();
    }
    
    @ApiOperation("成果-撤回")
    @GetMapping("/WithdrawAward")
    public Rest<Boolean> WithdrawAward(String id){
        boolean add = iAwardService.withdrawAward(id);
        return  add? Rest.success() : Rest.failed();
    }

    @ApiOperation("成果-名称查重")
    @GetMapping("/CheckAwardName")
    public Rest<Boolean> CheckAwardName(String awardname){
        boolean check= iAwardService.checkAwardName(awardname);
        return check ?Rest.success():Rest.failed();
    }

    @ApiOperation("根据主键成果查询")
    @GetMapping("/GetAwardbyID")
    public Rest<Award> GetAwardbyid(String awardid){
        Award award = iAwardService.getAward(awardid);
        return Rest.success(award);
    }

    @ApiOperation("根据主键成果DTO查询")
    @GetMapping("/GetAwardDTObyID")
    public Rest<AwardDTO> GetAwardDTObyid(String awardid){
        AwardDTO awarddto = iAwardService.getAwardDTOById(awardid);
        return Rest.success(awarddto);
    }

    @ApiOperation("成果-分页查询")
    @PostMapping("/pagecondition")
    public Rest<CommonPage<Award>> pageProjectCondition(@RequestBody SearchPageDTO searchPageDTO){
        IPage<Award> page = iAwardService.pageCondition(searchPageDTO);
        CommonPage<Award> activity = CommonPage.restPage(page);
        return Rest.success(activity);
    }
    @ApiOperation("成果-院级通过")
    @GetMapping("/CollegeCheckPass")
    public Rest<String> CollegePassAward(@RequestHeader("X-Token") String token,String PID){
        Boolean b = iAwardService.collegeCheckPass(token,PID);
        return b ? Rest.success() : Rest.failed();
    }
    @ApiOperation("成果-院级退回")
    @PostMapping("/CollegeCheckBack")
    public Rest<String> CollegeBackAward(@RequestHeader("X-Token") String token,@RequestBody CheckBackDTO checkBackDTO){
        Boolean b = iAwardService.collegeCheckBack(token,checkBackDTO);
        return b ? Rest.success() : Rest.failed();
    }
    @ApiOperation("成果-校级通过")
    @GetMapping("/SchoolCheckPass")
    public Rest<String> SchoolPassAward(@RequestHeader("X-Token") String token,String PID){
        Boolean b = iAwardService.schoolCheckPass(token,PID);
        return b ? Rest.success() : Rest.failed();
    }
    @ApiOperation("成果-校级退回")
    @PostMapping("/SchoolCheckBack")
    public Rest<String> SchoolBackAward(@RequestHeader("X-Token") String token,@RequestBody CheckBackDTO checkBackDTO){
        Boolean b = iAwardService.schoolCheckBack(token,checkBackDTO);
        return b ? Rest.success() : Rest.failed();
    }
    @ApiOperation("用户获取与自己相关的成果-分页")
    @PostMapping("/UserGetRelateAward")
    public Rest<CommonPage<AwardVO>> UserGetRelateAward(@RequestBody AwardPageQuery awardPageQuery){
        CommonPage<AwardVO> awardCommonPage =iAwardService.userGetRelateAward(awardPageQuery);
        return Rest.success(awardCommonPage);
    }
    @ApiOperation("成果-文件信息上传")
    @PostMapping("/addawardfile")
    public Rest<Boolean> addawardfile(@RequestBody Awardfile awardfile){
        boolean add = awardfileService.addAwardfile(awardfile);
        return add ? Rest.success() : Rest.failed();
    }
    @ApiOperation("成果-文件信息删除")
    @GetMapping("/Deleteawardfile")
    public Rest<Boolean> Deleteawardfile(String id)throws IOException {
        boolean delete = awardfileService.deleteAwardfile(id);
        return delete ? Rest.success() : Rest.failed();
    }
    @ApiOperation("成果-文件信息分页查询")
    @GetMapping ("/pageawardfileCondition")
    public Rest<List<Awardfile>> pageawardfileConditionfile(String id){
        List<Awardfile> page = awardfileService.pageAwardfile(id);
        return Rest.success(page);
    }
    @ApiOperation("成果-文件信息修改")
    @PostMapping("/updateawardfile")
    public Rest<Boolean> updateawardfile(@RequestBody Awardfile awardfile){
        boolean update = awardfileService.updateAwardfile(awardfile);
        return update ? Rest.success() : Rest.failed();
    }


    @ApiOperation("成果导出")
    @PostMapping("/export")
    public Rest<CommonPage<Award>> export(@RequestBody AwardPageQuery awardPageQuery) {
        CommonPage<Award> awardCommonPage = iAwardService.export(awardPageQuery);
        return Rest.success(awardCommonPage);
    }
}

